import request from '@/http/request'
import type { BasicResult, Key } from '@/api/_model/baseModel'
import type { LoginParams, LoginResultModel } from './model/userModel'
import type { RegisterParams, RegisterResultModel } from './model/userModel'
import type { GetUserParams, UserModel } from './model/userModel'

enum UserAPI {
  login = '/sys/adminLogin',
  register = '/sys/adminRegister',

  GetUserList = '/sys/user/list',
  AddUser = '/sys/user/add',
  EditUser = '/sys/user/update',
  DeleteUser = '/sys/user/',
  BatchDeleteUsers = '/sys/user/batch/',
  GetUserDetail = '/sys/user/',
  EditUserStatus = '/sys/user/setStatus',
  ResetPassword = '/sys/user/repass',
  checkUsernameExist = '/sys/user/check',
  GetUsersByIds = '/sys/user/select',
}

// 用户登录
export const loginApi = (params: LoginParams) =>
  request.post<LoginResultModel>(UserAPI.login, params)

// 用户注册
export const registerApi = (params: RegisterParams) =>
  request.post<RegisterResultModel>(UserAPI.register, params)

// 查询用户列表-分页
export const getUserList = (params: GetUserParams) =>
  request.get<BasicResult<UserModel>>(UserAPI.GetUserList, params)

// 增加用户
export const addUser = (params: UserModel) => request.post<any>(UserAPI.AddUser, params)

// 修改用户
export const editUser = (params: UserModel) => request.put<any>(UserAPI.EditUser, params)

// 删除用户
export const deleteUser = (params: Key) => request.delete<any>(UserAPI.DeleteUser + params)

// 批量删除用户
export const BatchDeleteUsers = (params: string) => request.delete<any>(UserAPI.DeleteUser + params)

// 查询用户详情
export const getUserDetail = (params: Key) => request.get<UserModel>(UserAPI.GetUserDetail + params)

// 修改用户状态
export const editUserStatus = (params: Pick<UserModel, 'id' | 'status'>) =>
  request.put<any>(UserAPI.EditUserStatus, params)

// 重置密码
export const resetPassword = (params: Pick<UserModel, 'id'>) =>
  request.post<any>(UserAPI.ResetPassword, params)

// 检查账号是否已存在
export const checkUsernameExist = (params: { name: UserModel['userName'] }) =>
  request.get<any>(UserAPI.checkUsernameExist, params)

// 根据用户名称获取用户列表
export const getUsersByIds = (params: { ids: string }) =>
  request.get<UserModel[]>(UserAPI.GetUsersByIds, params)
